<?php

require_once 'C:\wamp\www\projet_symfony\app_clinique\lib\fpdf/fpdf.php';


class patientActions extends autopatientActions
{

    public function executeShow(){
        $idpatient = $this->getRequestParameter('id');

        $this->patient = sfPatientPeer::retrieveByPk($idpatient);

        //liste des consultations du client
        $c = new Criteria();
        $c->add(sfConsultationPeer::PATIENT_ID, $idpatient);
        $c->addDescendingOrderByColumn(sfConsultationPeer::DATE);
        $this->listeconsultations = sfConsultationPeer::doselect($c);

        //liste des sejours du patient
        $c = new Criteria();
        $c->add(sfSejourPeer::PATIENT_ID, $idpatient);
        $c->addDescendingOrderByColumn(sfSejourPeer::DATE_DEBUT);
        $this->listeSejours = sfSejourPeer::doselect($c);
    
    }

    public function executePDF(){
        sfConfig::set('sf_web_debug', false);
        $idconsultation = $this->getRequestParameter('idconsultation');
        $this->consultation = sfConsultationPeer::retrieveByPk($idconsultation);
        $this->user = $this->consultation->getsfGuardUserProfile();
        $this->patient = $this->consultation->getsfPatient();
        //liste des traitements de la consultation
        $c = new Criteria();
        $c->add(sfTraitementPeer::CONSULTATION_ID, $idconsultation);
        $this->listetraitements = sfTraitementPeer::doselect($c);
    }
    

     public function executeList()
  {
    $this->processSort();

    $this->processFilters();

$this->filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/sf_patient/filters');

    // pager
    $this->pager = new sfPropelPager('sfPatient', 20);
    $c = new Criteria();
    $this->addSortCriteria($c);
    $this->addFiltersCriteria($c);
    $this->pager->setCriteria($c);
    $this->pager->setPage($this->getRequestParameter('page', $this->getUser()->getAttribute('page', 1, 'sf_admin/sf_patient')));
    $this->pager->init();
    // save page
    if ($this->getRequestParameter('page')) {
        $this->getUser()->setAttribute('page', $this->getRequestParameter('page'), 'sf_admin/sf_patient');
    }

    //$c = Criteria();
     //$this->listegroupes = sfGuardGroupPeer::doSelect($c);
  }

  public function executeEdit()
  {
    $this->sf_patient = $this->getsfPatientOrCreate();

    if ($this->getRequest()->getMethod() == sfRequest::POST)
    {
      $this->updatesfPatientFromRequest();

      $this->savesfPatient($this->sf_patient);

      $this->setFlash('notice', "L'enregistrement a été effectué");

      if ($this->getRequestParameter('save_and_add'))
      {
        return $this->redirect('patient/create');
      }
      else if ($this->getRequestParameter('save_and_list'))
      {
        return $this->redirect('patient/list');
      }
      else
      {
        return $this->redirect('patient/edit?id='.$this->sf_patient->getId());
      }
    }
    else
    {
      $this->labels = $this->getLabels();
    }
  }

}
